package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TourismRooms;
import com.ruoyi.system.service.ITourismRoomsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 民宿房间Controller
 *
 * @author gqd
 * @date 2020-12-29
 */
@RestController
@RequestMapping("/system/rooms")
public class TourismRoomsController extends BaseController
{
    @Autowired
    private ITourismRoomsService tourismRoomsService;

    /**
     * 查询民宿房间列表
     */
    @PreAuthorize("@ss.hasPermi('system:rooms:list')")
    @GetMapping("/list")
    public TableDataInfo list(TourismRooms tourismRooms)
    {
        startPage();
        List<TourismRooms> list = tourismRoomsService.selectTourismRoomsList(tourismRooms);
        return getDataTable(list);
    }

    /**
     * 导出民宿房间列表
     */
    @PreAuthorize("@ss.hasPermi('system:rooms:export')")
    @Log(title = "民宿房间", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TourismRooms tourismRooms)
    {
        List<TourismRooms> list = tourismRoomsService.selectTourismRoomsList(tourismRooms);
        ExcelUtil<TourismRooms> util = new ExcelUtil<TourismRooms>(TourismRooms.class);
        return util.exportExcel(list, "rooms");
    }

    /**
     * 获取民宿房间详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:rooms:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tourismRoomsService.selectTourismRoomsById(id));
    }

    /**
     * 新增民宿房间
     */
    @PreAuthorize("@ss.hasPermi('system:rooms:add')")
    @Log(title = "民宿房间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TourismRooms tourismRooms)
    {
        return toAjax(tourismRoomsService.insertTourismRooms(tourismRooms));
    }

    /**
     * 修改民宿房间
     */
    @PreAuthorize("@ss.hasPermi('system:rooms:edit')")
    @Log(title = "民宿房间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TourismRooms tourismRooms)
    {
        return toAjax(tourismRoomsService.updateTourismRooms(tourismRooms));
    }

    /**
     * 删除民宿房间
     */
    @PreAuthorize("@ss.hasPermi('system:rooms:remove')")
    @Log(title = "民宿房间", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tourismRoomsService.deleteTourismRoomsByIds(ids));
    }
}
